// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.specialist.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.request.QueryBaseReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.entity.Difficulty;
import com.liuxinlong.modules.entity.DifficultyPlan;
import com.liuxinlong.modules.specialist.controller.request.QueryDifficultyReq;
import com.liuxinlong.modules.specialist.controller.request.UpdateDifficultyPlanReq;
import com.liuxinlong.modules.specialist.controller.request.UpdateDifficultyReq;
import com.liuxinlong.modules.specialist.service.DifficultyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 技术难点信息管理控制层
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2023年3月8日
 */
@RestController
@RequestMapping("/difficulty")
public class DifficultyController {
    @Autowired
    private DifficultyService difficultyService;

    /**
     * 分页查询技术难点信息
     *
     * @param req 请求信息
     * @return 技术难点信息列表
     */
    @PostMapping("page")
    public BaseResp pageDifficultyInfo(@RequestBody QueryDifficultyReq req) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startNum", req.getStartNum());
        queryMap.put("pageSize", req.getPageSize());
        queryMap.put("projectId", req.getProjectId());
        queryMap.put("expert", req.getExpert());
        queryMap.put("status", req.getStatus());
        queryMap.put("pointType", req.getPointType());
        List<Map<String, Object>> dataList = difficultyService.pageDifficultyInfo(queryMap);
        int totalNum = difficultyService.getDifficultyCount(queryMap);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("分页查询技术难点信息成功");
        resp.setDataList(dataList);
        resp.setTotalNum(totalNum);
        return resp;
    }

    /**
     * 新增技术难点信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("add")
    @LogAnnotation(value = "新增技术难点信息", business = LogBusinessConstants.DIFFICULTY_MANAGE, operateType = LogOperateConstants.OPERATE_ADD)
    public BaseResp addDifficultyInfo(@RequestBody UpdateDifficultyReq req) {
        Difficulty difficulty = new Difficulty();

        difficulty.setProjectId(req.getProjectId());
        difficulty.setDifficultyName(req.getDifficultyName());
        difficulty.setLiableMember(req.getLiableMember());
        difficulty.setAssistExpert(req.getAssistExpert());
        difficulty.setExpiryDate(req.getExpiryDate());
        difficulty.setPointType(req.getPointType());
        difficulty.setFinishRate(req.getFinishRate());
        difficulty.setRemark(req.getRemark());
        difficultyService.addDifficultyInfo(difficulty);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("新增技术难点信息成功");
        return resp;

    }

    /**
     * 修改技术难点信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("update")
    @LogAnnotation(value = "更新技术难点信息", business = LogBusinessConstants.DIFFICULTY_MANAGE, operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updateDifficultyInfo(@RequestBody UpdateDifficultyReq req) {
        Difficulty difficulty = new Difficulty();
        difficulty.setId(req.getId());
        difficulty.setProjectId(req.getProjectId());
        difficulty.setDifficultyName(req.getDifficultyName());
        difficulty.setLiableMember(req.getLiableMember());
        difficulty.setAssistExpert(req.getAssistExpert());
        difficulty.setExpiryDate(req.getExpiryDate());
        difficulty.setFinishRate(req.getFinishRate());
        difficulty.setRemark(req.getRemark());
        difficultyService.updateDifficultyInfo(difficulty);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改技术难点信息成功");
        return resp;
    }

    /**
     * 删除技术难点信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("delete")
    @LogAnnotation(value = "删除技术难点信息", business = LogBusinessConstants.DIFFICULTY_MANAGE, operateType = LogOperateConstants.OPERATE_DELETE)
    public BaseResp deleteDifficultyInfo(@RequestBody BaseDeleteReq req) {
        difficultyService.deleteDifficultyInfo(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("删除技术难点信息成功");
        return resp;
    }

    /**
     * 导出技术难点信息
     *
     * @param req 请求信息
     * @return 导出数据
     */
    @PostMapping("export")
    @LogAnnotation(value = "导出技术难点信息", business = LogBusinessConstants.DIFFICULTY_MANAGE, operateType = LogOperateConstants.OPERATE_EXPORT)
    public void exportDifficultyInfo(@RequestBody QueryDifficultyReq req, HttpServletResponse response) {
        difficultyService.exportDifficultyInfo(req.getProjectId(),req.getPointType(), response);
    }

    /**
     * 分页查询专家方案信息
     *
     * @param req 请求信息
     * @return 专家方案信息列表
     */
    @PostMapping("plan-page")
    public BaseResp pageDifficultyPlanInfo(@RequestBody QueryBaseReq req) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startNum", req.getStartNum());
        queryMap.put("pageSize", req.getPageSize());
        queryMap.put("difficultyId", req.getId());
        List<Map<String, Object>> dataList = difficultyService.pageDifficultyPlanInfo(queryMap);
        int totalNum = difficultyService.getDifficultyPlanCount(queryMap);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("分页查询专家方案信息成功");
        resp.setDataList(dataList);
        resp.setTotalNum(totalNum);
        return resp;
    }

    /**
     * 新增专家方案信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("plan-add")
    @LogAnnotation(value = "新增专家方案信息", business = LogBusinessConstants.DIFFICULTY_MANAGE, operateType = LogOperateConstants.OPERATE_ADD)
    public BaseResp addDifficultyPlanInfo(@RequestBody UpdateDifficultyPlanReq req) {
        DifficultyPlan difficultyPlan = new DifficultyPlan();

        difficultyPlan.setDifficultyId(req.getDifficultyId());
        difficultyPlan.setExpertId(req.getExpertId());
        difficultyPlan.setContent(req.getContent());
        difficultyPlan.setSuggestTime(req.getSuggestTime());
        difficultyService.addDifficultyPlanInfo(difficultyPlan);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("新增专家方案信息成功");
        return resp;
    }

    /**
     * 修改技术难点信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("plan-update")
    @LogAnnotation(value = "更新专家方案信息", business = LogBusinessConstants.DIFFICULTY_MANAGE, operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updateDifficultyPlanInfo(@RequestBody UpdateDifficultyPlanReq req) {
        DifficultyPlan difficultyPlan = new DifficultyPlan();

        difficultyPlan.setId(req.getId());
        difficultyPlan.setDifficultyId(req.getDifficultyId());
        difficultyPlan.setExpertId(req.getExpertId());
        difficultyPlan.setContent(req.getContent());
        difficultyPlan.setSuggestTime(req.getSuggestTime());
        difficultyService.updateDifficultyPlanInfo(difficultyPlan);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改专家方案信息成功");
        return resp;
    }

    /**
     * 删除专家方案信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("plan-delete")
    @LogAnnotation(value = "删除专家方案信息", business = LogBusinessConstants.DIFFICULTY_MANAGE, operateType = LogOperateConstants.OPERATE_DELETE)
    public BaseResp deleteDifficultyPlanInfo(@RequestBody BaseDeleteReq req) {
        difficultyService.deleteDifficultyPlanInfo(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("删除专家方案信息成功");
        return resp;
    }

    /**
     * 导出专家方案信息
     *
     * @param req 请求信息
     * @return 导出数据
     */
    @PostMapping("plan-export")
    @LogAnnotation(value = "导出专家方案信息", business = LogBusinessConstants.DIFFICULTY_MANAGE, operateType = LogOperateConstants.OPERATE_EXPORT)
    public void exportDifficultyPlanInfo(@RequestBody BaseDeleteReq req, HttpServletResponse response) {
        difficultyService.exportDifficultyPlanInfo(req.getId(), response);
    }

    /**
     * 反馈专家方案信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("plan-feedback")
    @LogAnnotation(value = "反馈专家方案信息", business = LogBusinessConstants.DIFFICULTY_MANAGE, operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp feedbackDifficultyPlanInfo(@RequestBody UpdateDifficultyPlanReq req) {
        difficultyService.feedbackDifficultyPlanInfo(req.getId(),req.getFeedback());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("反馈专家方案信息成功");
        return resp;
    }
}
